<extend name="Layout/ins_page" />
<block name="content">
    <link href="/sap/demo.css" rel="stylesheet" type="text/css" />
    <script src="/sap/scripts/boot.js" type="text/javascript"></script>

    <div  id='maoliandxiaoshouForm'>
        <div class="fieldset-body">

            <!--<form method='post' id="maoliandxiaoshouForm" name="maoliandxiaoshouForm" enctype="multipart/form-data"   class="well form-horizontal">-->

            <div>
                物料名称: <input style="width: 360px" id="itemName" name="itemName" class="mini-textbox"/>
            </div>
            <div>
                <div id="listbox" name="listbox" class="mini-listbox" style="width:420px;height:120px;" onvaluechanged="onListBoxValueChanged"
                     url="/Report/getPingTaiList/" showCheckBox="true" multiSelect="true" >
                    <div property="columns">
                        <div header="平台代码" field="id"></div>
                        <div header="平台名称" field="text"></div>
                    </div>
                </div>
            </div>

            汇总方式：<div id="queryType" name="queryType" class="mini-radiobuttonlist" value="1" repeatItems="4" repeatDirection="horizontal" repeatLayout="table" data="[{'id':1,'text':'合并'},{'id':2,'text':'不合并'}]" textField="text" valueField="id" ></div>

            <div>
                <a class="mini-button" onclick="search()" enabled="" id='query-bt'  style="width:420px; margin-top: 5px">&nbsp;&nbsp;查询&nbsp;&nbsp;</a>
            </div>

            <div>
                <a class="mini-button" onclick="exportToexcel()" enabled="" id='export-bt'  style="width:420px; margin-top: 5px">&nbsp;&nbsp;导出&nbsp;&nbsp;</a>
            </div>
            <!--</form>-->

            <div id="tabs1" class="mini-tabs" activeIndex="0" style="width:100%;margin-top: 5px;overflow:auto;" plain="false"
                 buttons="#tabsButtons"
            >
                <div title="物料及库存查询" >

                    <div id="datagrid1" class="mini-datagrid" style="height:430px;width: 100%;"
                         url="/Report/wuliaojikucun20171018data" idField="id"
                         allowResize="true"
                         allowCellEdit="true" allowCellSelect="true" multiSelect="true"
                         allowCellValid="true" oncellvalidation="" showPager="false"
                    >

                        <div property="columns">

                            <div field="ItemCode"  headerAlign="center"  >物料号
                                <input property="" class="mini-textbox" style="width:100%;" />
                            </div>
                            <div field="ItemName"  headerAlign="center"  >物料描述
                                <input property="" class="mini-textbox" style="width:100%;" />
                            </div>
                            <div field="u_pmanager"  headerAlign="center"  >产品经理
                                <input property="" class="mini-textbox" style="width:100%;" />
                            </div>
                            <div field="grossweight"  headerAlign="center"  >称重
                                <input property="" class="mini-textbox" style="width:100%;" />
                            </div>
                            <div field="dataway"  headerAlign="center"  >称重方式
                                <input property="" class="mini-textbox" style="width:100%;" />
                            </div>
                            <div field="LeadTime"  headerAlign="center"  >采购提前
                                <input property="" class="mini-textbox" style="width:100%;" />
                            </div>
                            <div field="TrnspName"  headerAlign="center"  >包装方式
                                <input property="" class="mini-textbox" style="width:100%;" />
                            </div>
                            <div field="U_Brand"  headerAlign="center"  >品牌
                                <input property="" class="mini-textbox" style="width:100%;" />
                            </div>
                            <div field="U_Is3C"  headerAlign="center"  >3C
                                <input property="" class="mini-textbox" style="width:100%;" />
                            </div>
                            <div field="T_OnHand"  headerAlign="center"  >存货量
                                <input property="" class="mini-textbox" style="width:100%;" />
                            </div>
                            <div field="stockinWH"  headerAlign="center"  >在库库存
                                <input property="" class="mini-textbox" style="width:100%;" />
                            </div>
                            <div field="available"  headerAlign="center"  >可用库存
                                <input property="" class="mini-textbox" style="width:100%;" />
                            </div>
                            <div field="M_AVGPRICE"  headerAlign="center"  >库存价值
                                <input property="" class="mini-textbox" style="width:100%;" />
                            </div>
                            <div field="stockvalue"  headerAlign="center"  >库存总价值
                                <input property="" class="mini-textbox" style="width:100%;" />
                            </div>
                            <div field="sumpoorderqty"  headerAlign="center"  >总采购量
                                <input property="" class="mini-textbox" style="width:100%;" />
                            </div>

                            <div field="allsale" headerAlign="center"  >累计销量
                                <input property="" class="mini-textbox" style="width:100%;" />
                            </div>

                            <div field="allsalelastmonth" headerAlign="center"  >30天内销量
                                <input property="" class="mini-textbox" style="width:100%;" />
                            </div>

                            <div field="lastsale" headerAlign="center"  >最后出库时间
                                <input property="" class="mini-textbox" style="width:100%;" />
                            </div>

                            <div field="lastbuy" headerAlign="center"  >最早入库时间
                                <input property="" class="mini-textbox" style="width:100%;" />
                            </div>

                            <div field="windowsday" headerAlign="center"  >滞销天数
                                <input property="" class="mini-textbox" style="width:100%;" />
                            </div>

                            <div field="JDprice" headerAlign="center"  >京东价
                                <input property="" class="mini-textbox" style="width:100%;" />
                            </div>

                            <div field="TMprice" headerAlign="center"  >天猫价
                                <input property="" class="mini-textbox" style="width:100%;" />
                            </div>

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>


    </body>

    <script type="text/javascript">
        mini.parse();
        var grid = mini.get("datagrid1");
        grid.setPageSize(50000);
        grid.on("drawcell", function (e) {
            var record = e.record,
                column = e.column,
                field = e.field,
                value = e.value;

            //格式化日期
            if (field == "ctime") {
                if (mini.isDate(value)) e.cellHtml = mini.formatDate(value, "yyyy-MM-dd HH:mm:ss");

            }

            if (field == "relevant_link"||field == "similar_brand_link"||field == "top_link") {
                e.cellHtml = '<a href="' + value + '"  target="_blank"  >' +value+ '</a>';
            }

            if (field == "b_name") {
                var url="/SapSupplier/brandedit/id/";
                e.cellHtml = '<a href="' + url+record.b_id + '"  target="_blank"  >' +value+ '</a>';
            }

            if (field == "logo") {
                e.cellHtml = '<img src="' + value + '"  style="width:50px" >';
            }

            if (field == "s_price") {
                e.cellHtml = value+"<br>"+record.e_price;
            }

//            if(record.examine_status!=1)
//                e.cellStyle = "background:#f9a8a8";

            if (field == "examine_status") {
                e.cellHtml =value==1?"通过":(value==0?"待审核":'未通过') ;
            }

        });

        function onListBoxValueChanged(e) {
            var listbox = e.sender;
            var value = listbox.getValue();
        }

        function checkPT(ptlist) {

            if(ptlist){}
            else{
                alert('平台不能为空');
                return true;
            }
        }

        function checkItemName(itemName) {

            if(itemName){}
            else{
                alert('物料名称不能为空');
                return true;
            }
        }

        function search(){
            var itemName = mini.get('itemName').getValue();
            var ptlist = mini.get('listbox').getValue();
            var queryType = mini.get('queryType').getValue();

            if(checkItemName(itemName))
            {
                return;
            }

            if(checkPT(ptlist))
            {
                return;
            }

            grid.load({itemName:itemName,ptlist:ptlist,queryType:queryType})
        }

        function exportToexcel(){

            var itemName = mini.get('itemName').getValue();
            var ptlist = mini.get('listbox').getValue();
            var queryType = mini.get('queryType').getValue();

            if(checkItemName(itemName))
            {
                return;
            }

            if(checkPT(ptlist))
            {
                return;
            }

            var f=document.createElement("form");
            f.action="/Report/wuliaojikucun20171018excel";
            f.method="post";
            f.innerHTML=" <input type='hidden' name='itemName' value='"+itemName+"'/>"+
                "<input type='hidden' name='ptlist' value='"+ptlist+"'/>"+
                "<input type='hidden' name='queryType' value='"+queryType+"'/>"
            ;
            document.body.appendChild(f);
            f.submit();

        }

    </script>
</block>